﻿using System;

namespace HelloWorld
{
    /**
     * 使用c#编写我的第一个栈
     */
    public class MyStack<T>
    {
        private Entry<T> _top;
        
        public void push(T data)
        {
            Entry<T> newEntry = new Entry<T>(data);
            newEntry.setNext(this._top);
            this._top = newEntry;
        }

        public T pop()
        {
            if (this._top==null)
            {
                throw new Exception("栈为空");
            }

            Entry<T> newTop = this._top.getNext();

            T result = this._top.getData();
            this._top = newTop;
            return result;
        }
    }
}